//
//  NavigateItem.m
//  SecondPage
//
//  Created by winston on 13-4-24.
//  Copyright (c) 2013年 winston. All rights reserved.
//

#import "NavigateItem.h"

@implementation NavigateItem

@synthesize categoryName,colorName;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        unSelectedView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self addSubview:unSelectedView];
        [unSelectedView release];
        
        selectedView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self addSubview:selectedView];
        [selectedView release];
        
        arrowView = [[UIImageView alloc]initWithFrame:CGRectMake((frame.size.width-18)/2, 0, 18, 12)];
        [arrowView setImage:[UIImage imageNamed:@"AllAuto_Image_Arrow.png"]];
        [self addSubview:arrowView];
        [arrowView release];
        [arrowView setHidden:TRUE];
        
        self.selected = FALSE;
    }
    return self;
}

-(void)setCategory:(NSString*)category withImage:(NSString*)img
{
    self.categoryName = category;

//    NSLog(@"=====%@  %@",category,img);
    
    UIImage * image = [[UIImage alloc]initWithContentsOfFile:img];
    [unSelectedView setImage:image];
    [image release];
    
    NSString * selectImg = [img stringByReplacingOccurrencesOfString:category withString:[NSString stringWithFormat:@"%@_on",category]];
    image = [[UIImage alloc]initWithContentsOfFile:selectImg];
    [selectedView setImage:image];
    [image release];
}


-(void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    
    [arrowView setHidden:!selected];
    [selectedView setHidden:!selected];
    [unSelectedView setHidden:selected];
}

-(void)dealloc
{
    self.categoryName = nil;
    self.colorName = nil;
    [super dealloc];
}

@end
